package com.iwhalecloud.bss.kite.cucc.service.custview.userinfo.supplier;

import com.iwhalecloud.bss.kite.common.constant.KeyConsts;
import com.iwhalecloud.bss.kite.common.util.KiteMapUtils;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.service.custview.userinfo.UserAttrSupplier;
import com.iwhalecloud.bss.kite.dataservice.cache.AttrValueCache;
import com.iwhalecloud.bss.kite.dataservice.entity.AttrValue;
import com.ztesoft.common.logger.api.ZLogger;
import com.ztesoft.common.logger.factory.ZLoggerFactory;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * 15 计费类型
 */
@UserAttrSupplier(attrField = "ORD10240")
@Service
public class BillTypeSupplier extends AbstractUserAttrSupplier {

    private final ZLogger logger = ZLoggerFactory.getLogger(this.getClass(), KeyConsts.LOG_MODULE);
    @Override
    public String getValue() {
        String billTypeVal=null;
        try{
             billTypeVal = KiteMapUtils.getString(userInfoContext.getUserInfo(), "BILL_TYPE");
            if (KiteStringUtils.isEmpty(billTypeVal)) {
                billTypeVal = AttrValueCache.getAttrValue("2020111101", billTypeVal).getAttrValueName();
            }
        }catch (Exception e){
            logger.info("获取计费类型失败！");
        }

        return billTypeVal;
    }

    @Override
    public String getValueDesc() {
        String billTypeVal = getValue();
        return Optional.ofNullable(AttrValueCache.getAttrValue("2020111101", billTypeVal))
            .map(AttrValue::getAttrValueName).orElse(billTypeVal);
    }
}
